#include "Test.Application.h"

#undef  APP_NAME
#define APP_NAME	TestBatch
#undef  APP_BASE
#define APP_BASE	TestApp


class APP_NAME : public APP_BASE
{
protected:
	BatchMaterial	material;


public:
	APP_NAME (IPlatform *platform, EDevice::type deviceType) :
		APP_BASE( platform, deviceType )
	{}

	void Update (float dt) override
	{
		TestApp::Update( dt );

		ESS()->GetGraphicsEngine()->GetViewport()->Apply();
		ESS()->GetGLStateManager()->ClearColor( color4f( 1.0f ) );
		
		batch.AddBatch( material, Rect2D( rect(-0.95f, -0.45f, 0.7f, 0.95f), rect(), color4u(255, 0, 0, 120) ) );
		
		batch.AddBatch( material, Rect2D( rect(-0.1f, -0.95f, 0.95f, 0.3f), rect(), color4u(0, 255, 0, 120) ) );
		
		batch.AddBatch( material, Rect2D( rect(-0.4f, -0.4f, 0.4f, 0.4f), rect(), color4u(0, 100, 255, 120) ) );

		batch.AddBatch( material, Rect2D( rect(-0.6f, -0.9f, 0.4f, -0.55f), rect(), color4u(255, 0, 255, 180) ) );

		batch.Flush();
		batch.Clear();
		
		ESS()->GetGraphicsEngine()->SwapBuffers();
	}

	void OnEnter () override
	{
		APP_BASE::OnEnter();

		ProgramPtr		program = ESS()->GetGraphicsEngine()->GetShaderManager()->
								GetDefaultProgram( EDefaultShader::COLORED );

		material.SetProgram( program );
		
		RenderState::ColorState	cs;
		cs.blend		= true;
		cs.blendFuncSrc	= gl_blend_func::ONE_MINUS_SRC_ALPHA;
		cs.blendFuncDst	= gl_blend_func::SRC_ALPHA;

		material.SetColorState( cs );
	}

	void OnExit () override
	{
		material.Clear();
		APP_BASE::OnExit();
	}
};